/*
 * main implementation: use this 'C' sample to create your own application
 *
 */

#include "derivative.h" /* include peripheral declarations */

/* Macros */
#define rojo 0x00040000
#define verde 0x00080000
#define azul 0x00000002
#define RyV 0x000C0000

/* Functions */
void Azul ();
void Verde ();
void Rojo();
void (*semaforo[])()={Rojo,Verde,Azul};

/* Global variable */
int cnt;



int main()
{
	
	    SIM_SCGC5 = 0x00001400;  // Clock port B and D
		PORTB_PCR18 = PORTB_PCR19 = PORTD_PCR1=0x00000140;  //  GPIO mode
		GPIOB_PDDR |=RyV;  // Pins PTB18 and PTB19 as output
		GPIOD_PDDR |=azul; // Pin PTD1 as output
		GPIOB_PSOR =RyV; // clear port
		GPIOD_PSOR =azul;	//clear port
		
		while (1)
		{
			unsigned int i;
			for (i=0; i<=2;i++) //Select the index that calls the respective function
				(*semaforo[i])();
		}
	
	return 0;
}

void Azul ()
{
	  GPIOD_PCOR |=azul; // Set a low bit to port PTD1 
	  for(cnt=0;cnt<=1000000;cnt++); // Delay by software of 1 second
	  	  GPIOD_PSOR =azul;// Set a high bit to port PTD1 
}

void Verde ()
{
	 GPIOB_PCOR |=verde;// Set a low bit to port PTB19
	 for(cnt=0;cnt<=5000000;cnt++);// Delay by software of 5 second
	 	 GPIOB_PSOR =verde;// Set a high bit to port PTD2
}

void Rojo ()
{
	GPIOB_PCOR |=rojo;// Set a low bit to port PTB18
	for(cnt=0;cnt<=6000000;cnt++);// Delay by software of 6 second
		GPIOB_PSOR =rojo;// Set a high bit to port PTB18
}



